package com.own.demo.数据转换;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.own.demo.utils.FileToStringUtils;
import com.own.demo.writerfile.WriterFileUtils;
import com.own.demo.长沙空中路网格子.Common;

import java.io.File;
import java.util.List;

public class Main扇区 {

    public static void main(String[] args) {
        //起降点
        File geoZJ = new File("E:\\ownCode\\UMA\\数据\\数据static\\扇区");
        File[] dataFile = geoZJ.listFiles();
        int rowFile = dataFile.length;

        JSONObject voronoiLineData = Common.defaultObjectGsoJSONName("voronoiLineData");
        JSONObject voronoiPointData = Common.defaultObjectGsoJSONName("voronoiPointData");
        JSONObject voronoiPolygonData = Common.defaultObjectGsoJSONName("voronoiPolygonData");

        JSONObject trackLineData = Common.defaultObjectGsoJSONName("trackLineData");
        JSONObject trackSubdivisionData = Common.defaultObjectGsoJSONName("trackSubdivisionData");
        for (int w = 0; w < rowFile; w++) {
            File file = dataFile[w];
            String name = file.getName();
            JSONObject flieData=jsonData(file);
            //扇区划分
            if (name.startsWith("voronoi")) {
               // voronoiLineData.json
                if (name.startsWith("voronoiLineData")) {
                    voronoiLineData=flieData;
                }

                //voronoiPointData.json
                if (name.startsWith("voronoiPointData")) {
                    voronoiPointData=flieData;
                }
                // voronoiPolygonData.json
                if (name.startsWith("voronoiPolygonData")) {
                    voronoiPolygonData=flieData;
                }

            } else if (name.startsWith("track")) {
                //  trackLineData.json
                if (name.startsWith("trackLineData")) {
                    trackLineData=flieData;
                }
                 //  trackSubdivisionData.json
                if (name.startsWith("trackSubdivisionData")) {
                    trackSubdivisionData=flieData;
                }
            }
        }

        JSONObject all=Common.defaultObjectGsoJSONName("扇区");

        JSONObject voronoi=Common.defaultObjectGsoJSONName("扇区划分");
        voronoi.put("voronoiLineData",voronoiLineData);
        voronoi.put("voronoiPointData",voronoiPointData);
        voronoi.put("voronoiPolygonData",voronoiPolygonData);

        all.put("voronoi",voronoi);


        JSONObject track=Common.defaultObjectGsoJSONName("航线剖分");
        track.put("trackLineData",trackLineData);
        track.put("trackSubdivisionData",trackSubdivisionData);
        all.put("track",track);

        WriterFileUtils.writerFoFile(JSONObject.toJSONString(all),"E:\\ownCode\\UMA\\数据\\数据static\\成功数据","扇区.geojson");
        WriterFileUtils.writerFoFile(JSONObject.toJSONString(voronoi),"E:\\ownCode\\UMA\\数据\\数据static\\成功数据","扇区划分.geojson");
        WriterFileUtils.writerFoFile(JSONObject.toJSONString(track),"E:\\ownCode\\UMA\\数据\\数据static\\成功数据","轨迹剖分.geojson");
    }

    private static JSONObject jsonData(File file) {
        String geoData = FileToStringUtils.txt2String(file);
        JSONObject jsonObject = JSONObject.parseObject(geoData);
        return jsonObject.getJSONObject("data");
    }

}
